package com.chalmers.foa.gamemodel.gameobjects.other.impl;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import android.graphics.Bitmap;
import android.graphics.Point;

import com.chalmers.foa.gamemodel.events.IEvent;
import com.chalmers.foa.gamemodel.gameobjects.GameObjectAdapter;
import com.chalmers.foa.gamemodel.gameobjects.GameObjectBitmapAdapter;
import com.chalmers.foa.gamemodel.gameobjects.IGameObjectEventCastable;

public class Key extends GameObjectBitmapAdapter implements IGameObjectEventCastable {
	
	private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
	
	private GameObjectAdapter host;
	private IEvent event;
	
	public Key(Point position, Bitmap bitmap,int layer,int bound) {
		super(bitmap,position,layer,bound);
	}
	
	public Key(Bitmap bitmap) {
		this(new Point(0,0),bitmap,0,-1);
	}
	
	public void setHost(GameObjectAdapter object) {
		host = object;
	}
	
	public void update() {
		if(host != null)
			setPosition(new Point(host.getPosition().x, host.getPosition().y));
	}


	@Override
	public void addPropertyChangeListener(PropertyChangeListener pcl) {
		pcs.addPropertyChangeListener(pcl);
	}

	@Override
	public void bindEvent(IEvent _event) {
		event=_event;
	}

	@Override
	public void triggerEvent() {
		if(event!=null)
			pcs.firePropertyChange(new PropertyChangeEvent(this, "event", null, event));
	}

	@Override
	public boolean hasEvent() {
		return event!=null;
	}
	
}
